package com.zmzncs.shop.module.park.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.shop.common.pojo.PageInfo;
import com.zmzncs.shop.common.pojo.Rest;
import com.zmzncs.shop.common.util.JsonUtil;
import com.zmzncs.shop.common.util.RestUtil;
import com.zmzncs.shop.module.park.pojo.parkinfo.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.zmzncs.shop.module.park.service.ParkInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.constraints.NotNull;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rr
 * @since 2020-12-31
 */
@Api(tags = {"停车场"})
@RestController
@RequestMapping("/park/park-info")
public class ParkInfoController {

    @Autowired
    private ParkInfoService parkInfoService;


    @ApiOperation(value = "新增")
    @PostMapping("add")
    public Rest add(@RequestBody ParkInfoAddForm form){
        parkInfoService.add(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "删除")
    @PostMapping("delete")
    public Rest delete(@PathVariable Long id){
        parkInfoService.delete(id);

        return RestUtil.success();
    }

    @ApiOperation(value = "更新")
    @PostMapping("update")
    public Rest update(@RequestBody ParkInfoUpdateForm form){
        parkInfoService.update(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "查询分页数据")
    @GetMapping("page")
    public Rest<PageInfo<ParkInfoVO>> page(ParkInfoSearchForm form){
        IPage<ParkInfoDTO> iPage = parkInfoService.page(form);
        PageInfo<ParkInfoVO> pageInfo = JsonUtil.pageTransform(iPage, ParkInfoVO.class);

        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("get-by-id")
    public Rest<ParkInfoVO> getById(@RequestParam Long id){
        ParkInfoDTO parkInfoDTO = parkInfoService.getById(id);

        ParkInfoVO parkInfoVO = new ParkInfoVO();
        BeanUtils.copyProperties(parkInfoDTO, parkInfoVO);

        return RestUtil.success(parkInfoVO);
    }

}
